package hai.com.android_test.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import hai.com.android_test.R;

public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    List<String> datas;

    public MyAdapter(List<String> datas) {
        this.datas = datas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
        return new HoldNormal(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof HoldNormal) {
            ((HoldNormal) holder).tv.setText(datas.get(position));
        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    class HoldNormal extends RecyclerView.ViewHolder {
        TextView tv;

        public HoldNormal(View itemView) {
            super(itemView);
            tv = (TextView) itemView;
        }
    }
}